package com.meyoung.day3;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class regisTest {
    WebDriver driver;
    @BeforeMethod
    public void openchromeTest01() {
        //设置chromedriver路径
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\cll520\\IdeaProjects\\selenium11\\drivers\\chromedriver.exe");
        //实例化Chromedriver
        driver = new ChromeDriver();
    }
    @Test
    public void registest() throws InterruptedException {
        driver.get("https://mail.163.com/");
        Thread.sleep(3000);
        WebElement iframe = driver.findElement(By.tagName("iframe"));
        //把控制权转交iframe里面
        driver.switchTo().frame(iframe);
        //点击注册
        driver.findElement(By.linkText("注册网易邮箱")).click();
        //获取当前driver所在的handle值
        String handle1 = driver.getWindowHandle();
        //driver转换到新的window页面
        for (String handles :driver.getWindowHandles()){
            if (handles.equals(handle1)){
                continue;
            }
            driver.switchTo().window(handles);
        }
        driver.findElement(By.id("username")).sendKeys("a1533664666");
        driver.findElement(By.id("password")).sendKeys("123123123");
        driver.findElement(By.id("phone")).sendKeys("13819715553");
        driver.findElement(By.xpath("/html/body/div[2]/div/div/div[2]/div[2]/div[4]/span")).click();
        String text =driver.findElement(By.xpath("/html/body/div[2]/div/div/div[2]/div[2]/div[3]/div[1]/div[1]/div[1]")).getText();
        Assert.assertEquals(text,"手机扫描二维码，快速发送短信进行验证");
    }
    @AfterMethod
    public void closedBrowser(){
        driver.quit();
    }
}
